#define _CRT_SECURE_NO_WARNINGS
#include"stack.h"
void StackInitial(Stack* ps)
{
	assert(ps);
	ps->capacity = 4;
	ps->top = 0;
	ps->p = (STDataType*)calloc(4, sizeof(STDataType));
}
void StackPush(Stack* ps, STDataType x)
{
	assert(ps);
	if (ps->top == ps->capacity)
	{
		int newcapacity = 2 * ps->capacity;
		STDataType* t = (STDataType*)realloc(ps->p, newcapacity * sizeof(STDataType));
		assert(t);
		ps->p = t;
		ps->capacity = newcapacity;
	}
	ps->p[ps->top] = x;
	ps->top++;
}
void StackPop(Stack* ps)
{
	assert(ps);
	assert(ps->top > 0);
	ps->top--;
}
STDataType StackTop(Stack* ps)
{
	assert(ps);
	assert(ps->top > 0);
	return ps->p[ps->top - 1];
}
int StackSize(Stack* ps)
{
	assert(ps);
	return ps->top;
}
bool StackEmpty(Stack* ps)
{
	assert(ps);
	if (ps->top == 0)
		return true;
	else
		return false;
}
void StackDestroy(Stack* ps)
{
	assert(ps);
	free(ps->p);
	ps->p = NULL;
	free(ps);
}